package com.cskaoyan.main;

import com.mysql.jdbc.Driver;

import java.sql.*;

/**
 * 创建日期: 2022/06/30 09:33
 *
 * @author ciggar
 */
public class QueryDemo {

    public static void main(String[] args) throws SQLException {

        // 注册驱动
        DriverManager.registerDriver(new Driver());

        // 获取连接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/42th_rev?useSSL=false&characterEncoding=utf8",
          "root","123456");

        // 获取statement对象
        Statement statement = connection.createStatement();

        // 执行SQL语句
        ResultSet resultSet = statement.executeQuery("select * from student");


        // 解析结果集
        while (resultSet.next()) {


            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            String clazz = resultSet.getString("class");

            System.out.println("id:" + id + ",name:" + name + ",class:" + clazz);

        }

        // 关闭资源
        resultSet.close();
        statement.close();
        connection.close();



    }
}
